<?php

namespace App\Http\Controllers;

use App\Library\Lock;
use App\Library\Logic\OperateLogLogic;
use App\Library\Requests\Base\IdRequest;
use App\Library\Requests\Base\SerialNumberRequest;
use App\Library\Requests\Plug\PlugAddRequest;
use App\Library\Requests\Plug\PlugCreateRequest;
use App\Library\Requests\Plug\PlugEditRequest;
use App\Library\Requests\Plug\PlugPageRequest;
use App\Library\Requests\Product\ProductPageRequest;
use App\Library\Service\PlugService;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Carbon;

class PlugController extends BaseController
{
    /**
     * @param PlugService $service
     */
    public function __construct(PlugService $service)
    {
        $this->service = $service;
    }

    /**
     * create
     * @param PlugCreateRequest $request
     * @return JsonResponse
     */
    public function create(PlugCreateRequest $request): JsonResponse
    {
        return Lock::get('plugOrder:' . $request->serialNumber, function () use ($request) {
            return $this->service->create($request);
        });
    }

    /**
     * paging
     * @param PlugPageRequest $request
     * @return JsonResponse
     */
    public function paging(PlugPageRequest $request): JsonResponse
    {
        return $this->service->paging($request);
    }

    public function pList(ProductPageRequest $request): JsonResponse
    {
        return $this->service->pList($request);
    }
    public function list(ProductPageRequest $request): JsonResponse
    {
        return $this->service->list($request);
    }
    /**
     * add
     * @param PlugAddRequest $request
     * @return JsonResponse
     * @throws Exception
     */
    public function add(PlugAddRequest $request): JsonResponse
    {
        return $this->service->add($request);
    }

    /**
     * edit
     * @param PlugAddRequest $request
     * @return JsonResponse
     * @throws Exception
     */
    public function edit(PlugAddRequest $request): JsonResponse
    {
        return $this->service->edit($request);
    }

    /**
     * delete
     * @param SerialNumberRequest $request
     * @return JsonResponse
     * @throws Exception
     */
    public function del(SerialNumberRequest $request): JsonResponse
    {
        return $this->service->del($request);
    }

    /**
     * 产品详情
     * @param IdRequest $request
     * @return JsonResponse
     */
    public function detail(IdRequest $request): JsonResponse
    {
        return $this->service->detail($request);
    }

    public function upOrDown(SerialNumberRequest $request): JsonResponse
    {
        return $this->service->upOrDown($request);

    }
}
